package repository

import (
	"errors"
	"iris-starter/datamodels"
	"iris-starter/datasource"

	"gorm.io/gorm"
)

type IAdminUserRepo interface {
	Detail(id uint64) (*datamodels.AdminUser, error)
}

type AdminUserRepo struct {
}

func (a AdminUserRepo) Detail(id uint64) (*datamodels.AdminUser, error) {
	var u datamodels.AdminUser
	err := datasource.GDB.First(&u, id).Error
	if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
		return nil, err
	}
	return &u, nil
}

func NewAdminUserRepo() IAdminUserRepo {
	return &AdminUserRepo{}
}
